unit TextPosTest;

interface
uses System.SysUtils, Generics.Collections, Windows, AVUtils;

procedure TestTextPos;

implementation
const TestCount: integer = 1000000;
      TestText: string = 'IsBeginSubString some Text SomeText some Text IsSubString sometExt IsEndSUBstring';
      TestSubString: string = 'issubString';

//===============================

function AVContainText(Text, SubStr: string): integer; inline;
begin
  //Result := AVTextPos(Text, SubStr);
  Result := Pos(UpperCase(SubStr), UpperCase(Text));
end;

function AVContainTextNotInline(text, subString: string): integer;
begin
  Result := AVContainText(text, subString);
end;

//===============================

function GenTextList(count: integer): TList<string>;
var i: integer;
begin
  Result := TList<string>.Create;
  for i := 0 to count - 1 do
    Result.Add('IsBeginSubString some Text SomeText some Text IsSubString sometExt IsEndSUBstring');
end;

procedure TestTextPos;
var list: TList<string>;
    i: integer;
    startTick: DWord;
begin
  if AVContainText(TestText, TestSubString) = 0 then
  begin
    WriteLn('SubStrig not found');
    exit;
  end;

  startTick := GetTickCount;
  list := GenTextList(TestCount);
  try
    for i := 0 to list.Count - 1 do
    begin
      AVContainText(list[i], TestSubString);
      //AVContainTextNotInline(list[i], TestSubString);
    end;
  finally
    list.Free;
  end;
  WriteLn('Time: ' + IntToStr(GetTickCount - startTick));
end;

end.
